//
//  WYStrategyController.m
//  Boss
//
//  Created by admin on 2018/7/4.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYStrategyController.h"
#import "WYStrategyCell.h"
#import "WYStrategyModel.h"
#import "WYStrategyDetailController.h"
@interface WYStrategyController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIView *mainView;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation WYStrategyController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}

-(void)loadData
{
    WEAKSELF
    [WYHttpServer getStrategyListSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            [weakSelf.dataArray addObjectsFromArray:[WYStrategyModel getStrategyModelFromJson:response[@"result"]]];
            [weakSelf.tableView reloadData];
        }
        
        
    }];
}


-(void)setupUI
{
    self.mainView.width = self.scrollView.width;
    self.mainView.height = kScreenWidth*2290/375;
    self.scrollView.contentSize = self.mainView.size;
    [self.scrollView addSubview:self.mainView];
  //  [self wr_setNavBarBackgroundAlpha:0];
    [self wr_setNavBarShadowImageHidden:YES];
    self.navigationItem.title = @"玩法攻略";
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WYStrategyCell" bundle:nil] forCellReuseIdentifier:@"WYStrategyCell"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    WYStrategyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYStrategyCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYStrategyCell" owner:nil options:nil].firstObject;
    }
    WYStrategyModel *model =self.dataArray[indexPath.row];
    
    [cell setModel:model];
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYStrategyDetailController *sdc = [[WYStrategyDetailController alloc]init];
    WYStrategyModel *model =self.dataArray[indexPath.row];
    sdc.htmlString =model.content;
    sdc.titleName = model.firstName;
    [self.navigationController pushViewController:sdc animated:YES];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
